package com.bluedot.web.actions;

import java.util.Map;

import com.bluedot.domain.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
	private User user;

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String execute() throws Exception {
		if ("administ".equals(user.getUserName()) && "administ".equals(user.getPwd())) {
			ActionContext.getContext().getSession().put("user", user);
//			Map m =	ActionContext.getContext().getConversionErrors();
//			m.put("use", "���ȵ�½");
	//		System.out.println("2222");
			return SUCCESS;
		} else {
			//System.out.println("3333");
			return "input";
		}
	}

	public void validate() {
		//System.out.println("9999");
		if (user.getUserName() == null || user.getUserName().length() < 6
				|| user.getUserName().length() > 12) {
			addFieldError("user.userName", getText("user.username.invalid"));
//			System.out.println("88888");
		}
		if (user.getPwd() == null || user.getPwd().length() < 8
				|| user.getPwd().length() > 16) {
			addFieldError("user.pwd", "�����ʽ����Ӧ��Ϊ8��16λ���ַ�");
			
		}
	}
	
}
